import {PAGE_STATE} from '../../common/consts'
function connect(page, btnAreaCode, formId, billType, pkname, onMessage,dataSource){
    const { socket } = page.props;
    return socket.connectMesg({
        headBtnAreaCode: btnAreaCode,  // 表头按钮区域ID
        formAreaCode: formId, // 表头Form区域ID
        onMessage: onMessage&&onMessage.bind(page),//监听消息
        billtype: billType, //单据类型,用于查询追溯
        billpkname: pkname, //单据主键名,用于查询追溯
        dataSource:dataSource
        // serverLocation: "10.6.230.224:9991"// 本地前端调试，请传ip和端口
    })
}

function createErrorFlag(page, btnAreaCode){
    return page.props.button.createErrorFlag({
        headBtnAreaCode: btnAreaCode
    })
}

function toggleErrorStatus(page, pageStatus, sageFrozen, sageStatus, btnAreaCode){
    if(pageStatus != PAGE_STATE.BROWSE) return;
    page.props.button.toggleErrorStatus(btnAreaCode,{
        isError: sageStatus
    });
}

function onMessage(){
    let page = this;

}

const CardSocketUtils = {
    connect:connect,
    createErrorFlag:createErrorFlag,
    toggleErrorStatus:toggleErrorStatus,
    onMessage:onMessage
}

export default CardSocketUtils;